<template>
	<view>
		<view class="topTxt">
			<block v-if="timeData.seconds != 0">
				<u-count-down ref="countDown" @change="onChange" :time="startSeconds" format="ss"><text
						class="time__custom__item">{{ timeData.seconds }}s</text></u-count-down>
			</block>
			<view v-else>
				奖励已领取
			</view>
			<span style="margin: 0 10rpx;">|</span>
			<span @click="clickClose">关闭</span>
		</view>
		<view v-if="!show">
			<video autoplay show-fullscreen-btn="false" show-play-btn="false" http-cache="false"
				enable-progress-gesture="false" show-center-play-btn="false" controls="false"
				src="https://sou.yunluohudong.com/storage/shop_802/video/20230814/abd3d0a2ca2044da828c83e98bf0f0f1.mp4"></video>
		</view>
		<u-modal :content="content" :title="title" :show="show" closeOnClickOverlay showCancelButton
			@confirm="sureClose" @cancel="cancleClose"></u-modal>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				startSeconds: 10000,
				timeData: {},
				show: false,
				title: '温馨提醒',
				content: '此时关闭则无法完成任务，影响今日签到，确定要关闭吗？',
				sureclose: false,

			}
		},
		onLoad() {

			if (!this.hasLogin) {
				this.$api.msg('尚未登录，请先登录');
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}, 1000)
				return false;
			}
		},

		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},

		onBackPress() {
			if (this.timeData.seconds > 0) {
				if (!this.show) {
					this.show = true;
					return true;
				}

			}
		},
		methods: {
			onChange(e) {
				this.timeData = e;
			},

			cancleClose() {
				this.$refs.countDown.start();
				setTimeout(() => {
					this.show = false;
				}, 500)
			},

			clickClose() {
				if (this.timeData.seconds <= 0) {
					// uni.$emit('finishTask')
					var pages = getCurrentPages(); // 获取页面栈
					var prevPage = pages[pages.length - 2]; // 上一个页面
					prevPage.$vm.finishTask();
					setTimeout(() => {
						uni.navigateBack();
					}, 500)

					return
				}

				this.$refs.countDown.pause();
				this.show = true;
			},

			sureClose() {
				uni.redirectTo({
					url: '/pages/user/signin'
				})
			}
		}
	}
</script>

<style>
	page {
		overflow: hidden;
		background: #000;
	}

	.topTxt {
		font-size: 28rpx;
		color: #ffffff;
		padding: 70rpx 50rpx 0rpx 40rpx;
		background-color: black;
		display: flex;
		align-items: center;
		flex-direction: row;
		justify-content: flex-end;
		/* margin-top: 100rpx; */
	}

	video {
		width: 100vw;
		height: calc(100vh - 130rpx);
	}
</style>